﻿/*   */
$(function () {
    initChartsView_cbAndRk();//查补入库页面-分页统计、分局（科）统计、稽查入库统计

    function initChartsView_cbAndRk() {
        // 基于准备好的dom，初始化echarts实例
        let myChart_cbrkbymonth = echarts.init(document.getElementById('echarts_cbrkbymonth'));//查补入库按月统计
        let myChart_cbrkbyswjg = echarts.init(document.getElementById('echarts_cbrkbyswjg'));//查补入库按机关统计
        let myChart_jcrktj = echarts.init(document.getElementById('echarts_jcrktj'));//稽查入库统计
        //dataScope=数据权限：jcj(稽查局)、all(沈阳市局)
        CoreUtil.sendPost("/statistics/indexCbAndRkNew", null, function (res) {
            let cbDataByMonth = res.data.cbDataByMonth;
            let rkDataByMonth = res.data.rkDataByMonth;
            let cbDataBySwjg = res.data.cbDataBySwjg;
            let rkDataBySwjg = res.data.rkDataBySwjg;
            let jcrktj_categoryData = res.data.jcrktj_categoryData;
            let jcrktj_seriesData = res.data.jcrktj_seriesData;
            let cbrkbyswjg_xAxis_data = res.data.cbrkbyswjg_xAxis_data;
            let dataScope = res.data.dataScope;
            let option_cbrkByMonth = {
                title: {
                    text: '分月统计'
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['查补', '入库']
                },
                calculable: true,
                xAxis: [
                    {
                        type: 'category',
                        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: '查补',
                        type: 'bar',
                        data:
                        //     [
                        //     2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3
                        // ]
                        // ,
                        cbDataByMonth
                    },
                    {
                        name: '入库',
                        type: 'bar',
                        data:
                        //     [
                        //     2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3
                        // ]
                        // ,
                        rkDataByMonth
                    }
                ]
            };
            let title_swjg = "分科统计";
            if (dataScope === "all") {
                title_swjg = "分局统计";
            }
            let option_cbrkbyswjg = {
                title: {
                    text: title_swjg
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['查补', '入库']
                },
                calculable: true,
                xAxis: [
                    {
                        type: 'category',
                        data: cbrkbyswjg_xAxis_data
                        // ['全局', '一科', '二科', '三科', '四科', '五科']
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: '查补',
                        type: 'bar',
                        data:
                        //     [
                        //     135.6, 4.9, 7.0, 23.2, 25.6, 76.7
                        // ]
                        // ,
                        cbDataBySwjg
                    },
                    {
                        name: '入库',
                        type: 'bar',
                        data:
                        //     [
                        //     175.6, 5.9, 9.0, 26.4, 28.7, 70.7
                        // ]
                        // ,
                        rkDataBySwjg
                    }
                ]
            };
            let option_jcrktj = {
                title: {
                    text: '稽查入库统计'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                legend: {right: '20'},
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'value',
                    boundaryGap: [0, 0.01]
                },
                yAxis: {
                    type: 'category',
                    data:
                    // ['浑南','大东','沈河','和平', '辽中','新民', '于洪', '皇姑', '经开', '铁西', '全市']
                    // ,
                    jcrktj_categoryData
                },
                series: [
                    {
                        name: '单位:(万元)',
                        type: 'bar',
                        data:
                        // [18203, 18203, 18203, 18203, 18203, 18203, 23489, 29034, 104970, 131744, 630230]
                        // ,
                        jcrktj_seriesData
                    }
                ]
            };
            myChart_cbrkbymonth.setOption(option_cbrkByMonth);
            myChart_cbrkbyswjg.setOption(option_cbrkbyswjg);
            myChart_jcrktj.setOption(option_jcrktj);
        });
        window.addEventListener("resize", function () {
            myChart_cbrkbymonth.resize();
            myChart_cbrkbyswjg.resize();
            myChart_jcrktj.resize();
        });
    }
});

//查补入库
function switchCbRkToTable() {
    let div1 = document.getElementById("containerT1");
    let div2 = document.getElementById("containerT2");
    let divC1 = document.getElementById("echarts_cbrkbymonth");
    let divC2 = document.getElementById("echarts_cbrkbyswjg");
    let echarts_jcrktj = document.getElementById("echarts_jcrktj");
    if (divC1.style.display === "none") {
        divC1.style.display = "block";
        divC2.style.display = "block";
        echarts_jcrktj.style.display = "block";
        div1.style.display = "none";
        div2.style.display = "none";
        $("#cbrk").attr("class", "span8");
    } else {
        $("#containerT1_tbody").empty(); // 清空原有数据
        CoreUtil.sendPost("/statistics/chabuandruku", {"swjgDm": ""}, function (res) {
            let tableDatas = res.data.tableDatas;
            let tableHjDatas = res.data.tableHjDatas;//合计行
            let dataScope = res.data.dataScope;
            $.each(tableDatas, function (index, item) {
                let swjgmcTD = "";
                if ("all" === dataScope) {
                    swjgmcTD = "<td style='text-align: center'>" +
                        '<a href="javascript:void(0);" style="color:darkorchid" onclick=' +
                        '"xiazuanQ(' + item.swjgdm + ')">' +
                        item.swjgmc + "</a></td>";
                } else if ("jcj" === dataScope) {
                    swjgmcTD = "<td style='text-align: center'>" + item.swjgmc + "</td>";
                }
                let rowHtml = "<tr>" +
                    swjgmcTD +
                    "<td style='text-align: center;color:black'>" + item.cbskje + "</td>" + "<td style='text-align: center;color:black'>" + item.cbznjje + "</td>" +
                    "<td style='text-align: center;color:black'>" + item.cbmswfsdje + "</td><td style='text-align: center;color:black'>" + item.cbfkje + "</td>" +
                    "<td style='text-align: center;color:black'>" + item.cbzcje + "</td><td style='text-align: center;color:black'>" + item.cbhj + "</td>" +
                    "<td style='text-align: center;color:black'>" + item.rkskje + "</td><td style='text-align: center;color:black'>" + item.rkznjje + "</td>" +
                    "<td style='text-align: center;color:black'>" + item.rkmswfsdje + "</td><td style='text-align: center;color:black'>" + item.rkfkje + "</td>" +
                    "<td style='text-align: center;color:black'>" + item.rkzcje + "</td>" +"<td style='text-align: center;color:black'>" + item.rkhj + "</td>" +
                    "<td style='text-align: center;color:black'>" + item.rkqzdfj + "</td>" +
                    "</tr>";
                $("#containerT1_tbody").append(rowHtml);
            });
            //合计行
            let hjData = tableHjDatas[0];
            const hjrowhtml = "<tr>"
                + "<td style='text-align: center'>合计</td>"
                + "<td style='text-align: center;color:black'>" + hjData.cbskjetotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.cbznjjetotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.cbmswfsdjetotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.cbfkjetotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.cbzcjetotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.cbhjtotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.rkskjetotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.rkznjjetotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.rkmswfsdjetotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.rkfkjezstotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.rkzcjetotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.rkhjtotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.rkqzdfjtotal + "</td>"
                + "</tr>";
            $("#containerT1_tbody").append(hjrowhtml);
        });
        div1.style.display = "block";
        divC1.style.display = "none";
        divC2.style.display = "none";
        div2.style.display = "none";
        echarts_jcrktj.style.display = "none";
        $("#cbrk").attr("class", "span12");
    }
}

function xiazuanQ(swjgDm) {
    $("#containerT2_tbody").empty(); // 清空原有数据
    CoreUtil.sendPost("/statistics/chabuandruku", {"swjgDm": swjgDm}, function (res) {
        let tableDatas = res.data.tableDatas;
        let tableHjDatas = res.data.tableHjDatas;//合计行
        let dataScope = res.data.dataScope;
        $.each(tableDatas, function (index, item) {
            let swjgmcTD = "";
                swjgmcTD = "<td style='text-align: center'>" + item.swjgmc + "</td>";
            let rowHtml = "<tr>" +
                swjgmcTD +
                "<td style='text-align: center;color:black'>" + item.cbskje + "</td>" + "<td style='text-align: center;color:black'>" + item.cbznjje + "</td>" +
                "<td style='text-align: center;color:black'>" + item.cbmswfsdje + "</td><td style='text-align: center;color:black'>" + item.cbfkje + "</td>" +
                "<td style='text-align: center;color:black'>" + item.cbzcje + "</td><td style='text-align: center;color:black'>" + item.cbhj + "</td>" +
                "<td style='text-align: center;color:black'>" + item.rkskje + "</td><td style='text-align: center;color:black'>" + item.rkznjje + "</td>" +
                "<td style='text-align: center;color:black'>" + item.rkmswfsdje + "</td><td style='text-align: center;color:black'>" + item.rkfkje + "</td>" +
                "<td style='text-align: center;color:black'>" + item.rkzcje + "</td>" +"<td style='text-align: center;color:black'>" + item.rkhj + "</td>" +
                // "<td style='text-align: center;color:black'>" + item.RKQZDFJ + "</td>" +
                "</tr>";
            $("#containerT2_tbody").append(rowHtml);
        });
        //合计行
        let hjData = tableHjDatas[0];
        const hjrowhtml = "<tr>"
            + "<td style='text-align: center'>合计</td>"
            + "<td style='text-align: center;color:black'>" + hjData.cbskjetotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.cbznjjetotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.cbmswfsdjetotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.cbfkjetotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.cbzcjetotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.cbhjtotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.rkskjetotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.rkznjjetotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.rkmswfsdjetotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.rkfkjezstotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.rkzcjetotal + "</td>"
            + "<td style='text-align: center;color:black'>" + hjData.rkhjtotal + "</td>"
            // + "<td style='text-align: center;color:black'>" + hjData.rkqzdfjtotal + "</td>"
            + "</tr>";
        $("#containerT2_tbody").append(hjrowhtml);
    });
    let div1 = document.getElementById("containerT1");
    let div2 = document.getElementById("containerT2");
    let divC1 = document.getElementById("echarts_cbrkbymonth");
    let divC2 = document.getElementById("echarts_cbrkbyswjg");
    div1.style.display = "none";
    div2.style.display = "block";
    divC1.style.display = "none";
    divC2.style.display = "none";

}

function returnxiazuanQ() {
    let div1 = document.getElementById("containerT1");
    let div2 = document.getElementById("containerT2");
    let divC1 = document.getElementById("echarts_cbrkbymonth");
    let divC2 = document.getElementById("echarts_cbrkbyswjg");
    div1.style.display = "block";
    div2.style.display = "none";
    divC1.style.display = "none";
    divC2.style.display = "none";

}














